import requests


class IhrmEmpApi():

        # 定义添加员工方法
        @classmethod
        def add_emp(cls, header, req_data):
            resp = requests.post(
                url='http://192.168.246.130:8000/api/sys/user',
                headers=header,
                json=req_data
            )
            return resp

        # 定义查询员工方法
        @classmethod
        def query_emp(cls, emp_id, header):
            resp = requests.get(
                url='http://192.168.246.130:8000/api/sys/user/' + emp_id,
                headers=header
            )
            return resp

        # 定义修改员工方法
        @classmethod
        def modify_emp(cls, emp_id, header, req_data):
            resp = requests.put(
                url='http://192.168.246.130:8000/api/sys/user/' + emp_id,
                headers=header,
                json=req_data
            )
            return resp

        # 删除员工
        @classmethod
        def del_emp(cls, emp_id, header):
            return requests.delete(url='http://192.168.246.130:8000/api/sys/user/' + emp_id, headers=header)


if __name__ == '__main__':
    req_header = {"Authorization": "2a0edb44-d637-41b3-b861-d2fd681dd02c"}
    json = {
        "username": "user87655430",
        "mobile": "13947874780",
        "workNumber": "9527890aa"
    }
    response = IhrmEmpApi.add_emp(req_header, json)
    print('添加员工: ', response.json())

    modify_data = {"username": "放大镜考虑"}
    response = IhrmEmpApi.modify_emp('1902911925260476416', req_header, modify_data)
    print('修改员工: ', response.json())

    response = IhrmEmpApi.del_emp('1902911925260476416', req_header)
    print('删除员工: ', response.json())

    response = IhrmEmpApi.query_emp('1902911925260476416', req_header)
    print('查询员工: ', response.json())